package com.bdsy.business.controller;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import com.bdsy.business.model.ShopType;
import com.bdsy.business.service.ShopTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bdsy.api.annotation.IgnoreAuth;
import com.bdsy.business.model.ShopAuOrder;
import com.bdsy.business.service.ShopAuOrderService;
import com.bdsy.common.utils.Result;

@Controller
@RequestMapping(value = {"${web.adminPath}", "${web.appPath}"})
public class ShopAuOrderController {

	@Autowired
	private ShopAuOrderService shopAuOrderService;

    @Autowired
    ShopTypeService shopTypeService;

	/**
	 * 
	    * @Title: selectShopAuOrderById
	    * @Description: 查询竞拍订单信息
	 */
	@IgnoreAuth
	@RequestMapping("/selectShopAuOrderById")
	@ResponseBody
	public Object selectShopAuOrderById(int auOrderStatus, String userId) {
		List<Map> shopAuOrderList = shopAuOrderService.selectShopAuOrderById(auOrderStatus, userId);
		Map<String,Object> map = new LinkedHashMap<>();
		map.put("code", 200);
		map.put("msg", "success");
		map.put("shopAuOrderList",shopAuOrderList);
		return map;
	}
	
	/**
	 * 
	    * @Title: addshopAuOrder
	    * @Description: 添加竞拍信息
	 */
	@IgnoreAuth
	@RequestMapping("/addshopAuOrder")
	@ResponseBody
	public Object addshopAuOrder(ShopAuOrder shopAuOrder) {
		boolean result = shopAuOrderService.add(shopAuOrder);
		if (result) {
			return Result.ok("添加成功");
		} else {
			return Result.error("添加失败");
		}
	}
	
	/**
	 * 
	    * @Title: updateShopAuOrder
	    * @Description: 修改订单状态
	 */
	@IgnoreAuth
	@RequestMapping("/updateShopAuOrder")
	@ResponseBody
	public Object updateShopAuOrder(ShopAuOrder shopAuOrder) {
		boolean result = shopAuOrderService.update(shopAuOrder);
		if (result) {
			return Result.ok("修改成功");
		} else {
			return Result.error("修改失败");
		}
	}

    /**
     * 跳转页面
     * @return
     */
    @RequestMapping(value ="auorder")
	public String auorder(Model model){
        List<ShopType> shopTypeInfo = shopTypeService.shopTypeInfo();
        if (!shopTypeInfo.isEmpty()) {
            model.addAttribute("shopTypeInfo", shopTypeInfo);
        }
	    return "admin/business/auorder";
    }



    /**
     *  查询竞拍订单信息
     * @param auOrderStatus
     * @param shopTypeId
     * @param userId
     * @return
     */
    @RequestMapping("/selectAuOrderByTypeOrStatus")
    @ResponseBody
    public Object selectAuOrderByTypeOrStatus(int auOrderStatus,int shopTypeId,String userId) {
        List<Map> shopAuOrderList = shopAuOrderService.selectAuOrderByTypeOrStatus(auOrderStatus, shopTypeId, userId);
        return shopAuOrderList;
    }


    /**
     * 修改租赁订单状态
     * @param shopAuOrder
     * @return
     */
    @RequestMapping("/updateShopAuOrderStatus")
    @ResponseBody
    public Object updateShopAuOrderStatus(ShopAuOrder shopAuOrder) {
        boolean result = shopAuOrderService.update(shopAuOrder);
        if (result) {
            return Result.ok("修改成功");
        } else {
            return Result.error("修改失败");
        }
    }
}
